<!DOCTYPE html>
<html lang="en"class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>发表问题 编辑问题 公用</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="fly,layui,前端社区">
  <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
  <link rel="stylesheet" href="../../res/layui/css/layui.css">
  <link rel="stylesheet" href="../../res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
  <div class="layui-container">
    <a class="fly-logo" href="/">
      <img src="../../res/images/logo.png" alt="layui">
    </a>
    <ul class="layui-nav fly-nav layui-hide-xs">
      <li class="layui-nav-item layui-this">
        <a href="/"><i class="iconfont icon-jiaoliu"></i>交流</a>
      </li>
      <li class="layui-nav-item">
        <a href="../case/case.html"><i class="iconfont icon-iconmingxinganli"></i>案例</a>
      </li>
      <li class="layui-nav-item">
        <a href="http://www.layui.com/" target="_blank"><i class="iconfont icon-ui"></i>框架</a>
      </li>
    </ul>
    
    <ul class="layui-nav fly-nav-user">
      
      <!-- 未登入的状态 -->
      <!--
      <li class="layui-nav-item">
        <a class="iconfont icon-touxiang layui-hide-xs" href="user/login.html"></a>
      </li>
      <li class="layui-nav-item">
        <a href="user/login.html">登入</a>
      </li>
      <li class="layui-nav-item">
        <a href="user/reg.html">注册</a>
      </li>
      <li class="layui-nav-item layui-hide-xs">
        <a href="/app/qq/" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" title="QQ登入" class="iconfont icon-qq"></a>
      </li>
      <li class="layui-nav-item layui-hide-xs">
        <a href="/app/weibo/" onclick="layer.msg('正在通过微博登入', {icon:16, shade: 0.1, time:0})" title="微博登入" class="iconfont icon-weibo"></a>
      </li>
       -->
      
      <!-- 登入后的状态 -->
      <li class="layui-nav-item">
        <a class="fly-nav-avatar" href="javascript:;">
          <cite class="layui-hide-xs">[[${session.user.account}]]</cite>
          <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>
          <i class="layui-badge fly-badge-vip layui-hide-xs">Level[[${session.user.level}]]</i>
          <!-- 默认的头像-->
          <img src="https://tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg">
        </a>
        <dl class="layui-nav-child">
          <dd><a th:href="@{/user/set}"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
          <dd><a th:href="@{/user/message}"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a></dd>
          <dd><a th:href="@{/user/home}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
          <hr style="margin: 5px 0;">
          <dd><a href="" style="text-align: center;">退出</a></dd>
        </dl>
      </li>
    </ul>
  </div>
</div>

<div class="layui-container fly-marginTop">
  <div class="fly-panel" pad20 style="padding-top: 5px;">
    <!--<div class="fly-none">没有权限</div>-->
    <div class="layui-form layui-form-pane">
      <div class="layui-tab layui-tab-brief" lay-filter="submitBtn">
        <ul class="layui-tab-title">
          <li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
        </ul>
        <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
          <div class="layui-tab-item layui-show">
            <form class="layui-form" lay-filter="submitBtn"
                  enctype="multipart/form-data">
              <input type="hidden" name="articleId" >
              <input type="hidden" name="articleUserId" th:value="${session.user.id}">
              <div class="layui-row layui-col-space15 layui-form-item">

                <div class="layui-col-md3">
                  <label class="layui-form-label">所在专栏</label>
                  <div class="layui-input-block">
                    <select lay-verify="required" name="typeId" >
                      <option value="">请选择文章类型</option>
                      <option th:each="articleType:${articleTypes}" th:value="${articleType.typeId}" th:text="${articleType.name}"></option>
                    </select>
                  </div>
                </div>

                <div class="layui-col-md9">
                  <label for="L_title" class="layui-form-label">标题</label>
                  <div class="layui-input-block">
                    <input type="text" id="L_title" name="title"  lay-verify="required" autocomplete="off" class="layui-input">
                  </div>
                </div>
              </div>

              <div class="layui-form-item layui-form-text">
                <div class="layui-input-block">
                    <textarea name="content" id="edit" cols="30" rows="10"></textarea>
                </div>
              </div>
              <div class="layui-form-item">
<!--                <button class="layui-btn" lay-event="getContent">立即发布</button>-->

                <button class="layui-btn" lay-filter="submitBtn" lay-event="getContent" lay-submit>立即发布</button>
              </div>
            </form>

          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="fly-footer">
  <p><a href="http://fly.layui.com/" target="_blank">Fly社区</a> 2017 &copy; <a href="http://www.layui.com/" target="_blank">layui.com 出品</a></p>
  <p>
    <a href="http://fly.layui.com/jie/3147/" target="_blank">付费计划</a>
    <a href="http://www.layui.com/template/fly/" target="_blank">获取Fly社区模版</a>
    <a href="http://fly.layui.com/jie/2461/" target="_blank">微信公众号</a>
  </p>
</div>

<script src="../../res/layui/layui.js"></script>
<script>
  // /^http(s*):\/\//.test(location.href) || alert('请先部署到 localhost 下再访问');
  layui.extend({
    tinymce: '/res/libs/tinymce/tinymce'
  }).use(['tinymce','layer', 'form','jquery', 'util'], function(){
    var layer = layui.layer
            ,form = layui.form
            ,$ =layui.jquery;
      var tinymce = layui.tinymce;

      var util = layui.util;

      var edit = tinymce.render({
          elem: "#edit"
          , height: 600
      });

      util.event('lay-event', {
          getContent: function () {
              console.log(edit.getContent())
          }
      });

    //如果成功跳转到个人的主页
    form.on('submit(submitBtn)', function(data){
      var user = data.field;
      user.content = edit.getContent();
      console.log("data: "+JSON.stringify(user));

      $.post("/article/addArticle",user,function(d){
        if (d.code == 0) {
          layer.msg("文章提交成功,等待审核！");

          //刷新父页面
          //parent.location.reload();
        } else {
          layer.msg(d.message,{"icon":2});
        }
      });

      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });


  });
</script>

</body>
</html>